/*
 * @lc app=leetcode.cn id=700 lang=javascript
 *
 * [700] 二叉搜索树中的搜索
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @param {number} val
 * @return {TreeNode}
 */
var searchBST = function(root, val) {
    if(!root)return null
    if(val>root.val){
        return searchBST(root.right,val)
    }else if(val<root.val){
        return searchBST(root.left,val)
    }else{
        return root
    }
};
// @lc code=end
searchBST({val:4,right:{val:7,left:null,right:null},left:{val:2,left:{val:1,left:null,right:null},right:{val:3,left:null,right:null}}},5)
